package Chuong04;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class Bai02 extends JFrame implements ActionListener{

	int i = 0;
	JPanel p = new JPanel();
	JLabel l1 = new JLabel("   ");
	JLabel l2 = new JLabel("   ");
	JLabel l3 = new JLabel("   ");
	JLabel l4 = new JLabel("   ");
	JLabel l5 = new JLabel("Number of button click: 0");
	JButton btnClick = new JButton("I am a Swing button!");
	
	public Bai02(){
		setSize(300,120);
	    setTitle("Bài 02 - Chương 04");
	    btnClick.addActionListener(this);
	    Container contentPane = getContentPane();

	    p.add(btnClick); p.add(l5);
	    
	    contentPane.add(l1, BorderLayout.NORTH);
        contentPane.add(p, BorderLayout.CENTER);
        contentPane.add(l2, BorderLayout.WEST);
        contentPane.add(l3, BorderLayout.SOUTH);
        contentPane.add(l4, BorderLayout.EAST);
	}
    
    public static void main(String args[]) {
    	Bai02 frm = new Bai02();
    	frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	frm.setVisible(true);
    }

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == btnClick){
			i++;
			l5.setText("Number of button click: " + String.valueOf(i));
		}
		
	}
}
